package com.loveyukari.controller;

import java.io.IOException;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.loveyukari.support.JsonResult;

/**
*
*yangshaohua
*2017年6月22日下午2:07:14
**/
@Controller
@RequestMapping("/admin/file")
public class FileController {

	@RequestMapping("/parseLrc")
	@ResponseBody
	public JsonResult<Object> parseLrc(MultipartFile file){
		JsonResult<Object> result = new JsonResult<Object>();
		try {
			String str = new String(file.getBytes());
			String[] split = str.replace("\r", "").split("\n");
			StringBuilder sb = new StringBuilder();
			for (int i = 0; i < split.length; i++) {
				String line = split[i];
				if (StringUtils.isBlank(line)){
					continue;
				}
				if (line.startsWith("[")){
					line = line.substring(line.indexOf("]")+1);
				}
				sb.append(line).append("\r\n");
			}
			result.setData(sb.toString());
		} catch (IOException e) {
			result.setData("");
		}
		return result;
	}
	
	
}
